package com.chen.controller;

import com.chen.common.Result;
import com.chen.pojo.User;
import com.chen.pojo.bean.UserInfo;
import com.chen.service.Impl.LoginServiceImpl;
import com.chen.service.Impl.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chenchao

 */
@RestController
@Api(value = "LoginController", tags = "账户操作")
@RequestMapping("/user")
@SuppressWarnings("all")
@Slf4j
public class LoginController {

    @Resource
    private LoginServiceImpl userService;


    @Resource
    private MailService mailService;



    //发送邮件
    @PostMapping("/sendEmail/{username}")
    public Result<?> sendEmail(@PathVariable("username") String username,  String code){
        System.out.println(username);

        return mailService.sendMimeMail(username, code);
    }



    //    登录
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result<?> login(@RequestBody User user) {
        return userService.login(user);
    }


    //注册
    @PostMapping("/register")
    @ApiOperation("注册")
    public Result<?> register(@RequestBody User user) {
        return userService.register(user);
    }

    //忘记密码
    @PutMapping("/forget")
    @ApiOperation("忘记密码")
    public Result<?> forget(@RequestBody User user){
        return userService.forget(user);
    }

    @DeleteMapping("/logout/{id}")
    @ApiOperation("注销")
    public Result<?> logout(@PathVariable("id") Long id){
        return userService.logout(id);
    }



}
